package pluginGraphe;

import application.IPlugin;
import application.ViewManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JComponent;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;


public class Graphe implements IPlugin, ActionListener{
    
    private IVueGraphe vue;
    private JMenuItem item;
    
    public JComponent creerGrapheBar() {
        JPanel panel = new JPanel();
        vue = new VueBar();
        PlageCellule plage = new PlageCellule();
        GraphePlageCellule graph= new GraphePlageCellule(vue, plage);
        plage.addObserver(graph);
        panel.add(graph);
        panel.validate();
        return panel;
    }

    public JComponent creerGrapheCamanbert(){
        JPanel panel = new JPanel();
        vue = new VueCamembert();
        PlageCellule plage = new PlageCellule();
        GraphePlageCellule graph = new GraphePlageCellule(vue, plage);
        plage.addObserver(graph);
        panel.add(graph);
        panel.validate();

        return panel;
    }
    
    @Override
    public String getName() {
        return "Graphe ";
    }

    @Override
    public JMenu getMenu() {
        JMenu menuGraphe = new JMenu();
        item = new JMenuItem("Histogramme");
        item.setActionCommand("histogramme");
        item.addActionListener(this);
        menuGraphe.add(item);
        item = new JMenuItem("Camembert");
        item.setActionCommand("camembert");
        item.addActionListener(this);
        menuGraphe.add(item);
        return menuGraphe;
        
    }

    @Override
    public void addTable() {
        
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        switch (e.getActionCommand()) {
            case "histogramme":
                ViewManager.getInstance().displayGraphe(creerGrapheBar());
                break;
            case "camembert":
                ViewManager.getInstance().displayGraphe(creerGrapheCamanbert());
                break;
        }
    }
    
    

}
